package com.test.dababy.dababy_05_process;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import com.test.dababy.R;
import com.test.dababy.dababy_00_utils.DababyUtil;
import com.test.dababy.dababy_01_launcher.App_dababyShow_dababyCustomize;
import com.test.dababy.dababy_00_http.OkHttpUtil;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;


public class Delete_dababyAccountDi_dababyalog_Fr extends Dialog {


    private char h7e7='À';
    private char pu1n='';
    private int wzkb=87;
    private String eqwh="";
    private String ihjJ="";
    private float bu7m=0.17534924f;
    private float rhmJ=0.71264f;
    private double iPI4=0.5545573588376466;
    private char zwPD='3';
    private float u1G4=0.63986313f;
    private int k49B=213;
    private char wpXr='i';
    private double bvE8=0.3389372394702739;
    private boolean jzb9=true;
    private boolean mDj7=false;
    private int j47h=53;

    public void c0207(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getEqwh())) setIhjJ(String.valueOf(getH7e7())+getPu1n()+getWzkb()+getBu7m()+getRhmJ()+getiPI4());
                else setIhjJ(String.valueOf(getZwPD())+getU1G4()+getK49B()+getWpXr()+getBvE8()+isJzb9()+ismDj7()+getJ47h());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setH7e7(char h7e7) {
        this.h7e7 = h7e7;
    }

    public void setPu1n(char pu1n) {
        this.pu1n = pu1n;
    }

    public void setWzkb(int wzkb) {
        this.wzkb = wzkb;
    }

    public void setEqwh(String eqwh) {
        this.eqwh = eqwh;
    }

    public void setIhjJ(String ihjJ) {
        this.ihjJ = ihjJ;
    }

    public void setBu7m(float bu7m) {
        this.bu7m = bu7m;
    }

    public void setRhmJ(float rhmJ) {
        this.rhmJ = rhmJ;
    }

    public void setiPI4(double iPI4) {
        this.iPI4 = iPI4;
    }

    public void setZwPD(char zwPD) {
        this.zwPD = zwPD;
    }

    public void setU1G4(float u1G4) {
        this.u1G4 = u1G4;
    }

    public void setK49B(int k49B) {
        this.k49B = k49B;
    }

    public void setWpXr(char wpXr) {
        this.wpXr = wpXr;
    }

    public void setBvE8(double bvE8) {
        this.bvE8 = bvE8;
    }

    public void setJzb9(boolean jzb9) {
        this.jzb9 = jzb9;
    }

    public void setmDj7(boolean mDj7) {
        this.mDj7 = mDj7;
    }

    public void setJ47h(int j47h) {
        this.j47h = j47h;
    }

    public char getH7e7() {
        return h7e7;
    }

    public char getPu1n() {
        return pu1n;
    }

    public int getWzkb() {
        return wzkb;
    }

    public String getEqwh() {
        return eqwh;
    }

    public String getIhjJ() {
        return ihjJ;
    }

    public float getBu7m() {
        return bu7m;
    }

    public float getRhmJ() {
        return rhmJ;
    }

    public double getiPI4() {
        return iPI4;
    }

    public char getZwPD() {
        return zwPD;
    }

    public float getU1G4() {
        return u1G4;
    }

    public int getK49B() {
        return k49B;
    }

    public char getWpXr() {
        return wpXr;
    }

    public double getBvE8() {
        return bvE8;
    }

    public boolean isJzb9() {
        return jzb9;
    }

    public boolean ismDj7() {
        return mDj7;
    }

    public int getJ47h() {
        return j47h;
    }

    private final Ba_dababynkAcc_dababyount_Fr account_dababy;

    private final String page_dababy;

    private final Runnable dltActRespRunnable_dababy;

    public Delete_dababyAccountDi_dababyalog_Fr(@NonNull FragmentActivity activity,
                                                    Ba_dababynkAcc_dababyount_Fr account,
                                                    String page,
                                                    Runnable dltActRespRunnable) {
        super(activity);
        this.account_dababy = account;
        this.page_dababy = page;
        this.dltActRespRunnable_dababy = dltActRespRunnable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_dababy_delete_account_fr);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        initView_dababy();
    }

    @SuppressLint("SetTextI18n")
    private void initView_dababy(){

        TextView accountmobileTv  = findViewById(R.id.dddaf_tv_mobile);
        ImageView accountlogoIv = findViewById(R.id.dddaf_iv_logo);
        TextView accountchannelTv = findViewById(R.id.dddaf_tv_channel);

        findViewById(R.id.dddaf_ib_close).setOnClickListener(v -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint(page_dababy,"_DELETE_CANCEL_CLICK", account_dababy.getWalletMobile_dababy());
            dismiss();
        });

        //取消
        findViewById(R.id.dddaf_btn_cancel).setOnClickListener(v -> {
            OkHttpUtil.getInstance_dababy().uploadEventPoint(page_dababy,"_DELETE_CANCEL_CLICK", account_dababy.getWalletMobile_dababy());
            dismiss();
        });

        //提交
        findViewById(R.id.dddaf_btn_submit).setOnClickListener(v -> {
            DababyUtil.startLoading(getContext(),"");
            OkHttpUtil.getInstance_dababy().uploadEventPoint(page_dababy,"_DELETE_CONFIRM_CLICK", account_dababy.getWalletMobile_dababy());
            OkHttpUtil.getInstance_dababy().deleteWalletAccount_Fr(account_dababy.getId_dababy(),() -> {
                if (dltActRespRunnable_dababy !=null) dltActRespRunnable_dababy.run();
            });
            dismiss();
        });

        if (account_dababy != null){

            String channelDesc = account_dababy.getWalletDesc_dababy();

            accountmobileTv.setText(account_dababy.getWalletMobile_dababy());
            accountchannelTv.setText(channelDesc);

            c0207();

            //加载图标
            if (App_dababyShow_dababyCustomize.getInstance_dababy().getChannelLogoByDesc_dababy(channelDesc) == null){
                new Thread(() -> {
                    try {
                        if (TextUtils.isEmpty(account_dababy.getWalletLogo_dababy())) return;
                        if (!App_dababyShow_dababyCustomize.getInstance_dababy().hasAccountChannel_dababy()) return;
                        URL url = new URL(account_dababy.getWalletLogo_dababy());
                        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                        connection.setConnectTimeout(5000);
                        connection.setRequestMethod("GET");
                        if (connection.getResponseCode()==200){
                            InputStream inputStream = connection.getInputStream();
                            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                            App_dababyShow_dababyCustomize.getInstance_dababy().setChannelLogoByDesc_dababy(channelDesc,bitmap);
                            DababyUtil.safeRun(() -> accountlogoIv.setImageBitmap(bitmap));
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }).start();
            }else accountlogoIv.setImageBitmap(App_dababyShow_dababyCustomize.getInstance_dababy().getChannelLogoByDesc_dababy(channelDesc));

        }

    }

}
